package com.loby.monitor.excess.local;

import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.*;

/**
 * 存放所有排放口报警信息容器
 * @author loby
 */
@Slf4j
public class ExcessInfoContainer implements List<ExcessInfoItem>, Serializable {
    private String clientCode;
    ArrayList<ExcessInfoItem> container;
    String alarmExcessModeKeys = null;

    String alarmCompositeCodes = null;
    private transient boolean isExcess;
    private transient boolean isAbnormal;

    public  ExcessInfoContainer()
    {
        super();
        container = new ArrayList<>();
    }

    public boolean isExcess() {
        return isExcess;
    }

    public boolean isAbnormal() {
        return isAbnormal;
    }

    public ExcessInfoContainer(String clientCode) {
        this.clientCode = clientCode;
    }

    public String getClientCode()
    {
        return clientCode;
    }

    @Override
    public int size() {
        return container.size();
    }

    @Override
    public boolean isEmpty() {
        return container.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return container.contains(o);
    }

    @Override
    public Iterator<ExcessInfoItem> iterator() {
        return container.iterator();
    }

    @Override
    public Object[] toArray() {
        return container.toArray();
    }

    @Override
    public <T> T[] toArray(T[] ts) {
        return container.toArray(ts);
    }

    @Override
    public boolean add(ExcessInfoItem excessInfoItem) {

        if(alarmExcessModeKeys == null) {
            alarmExcessModeKeys = excessInfoItem.getExcessMode().getKey();
        } else {
            alarmExcessModeKeys = alarmExcessModeKeys +","+excessInfoItem.getExcessMode().getKey();
        }
        if(alarmCompositeCodes == null)
        { alarmCompositeCodes = excessInfoItem.getCompositionCode();}
        else {
            alarmCompositeCodes = alarmCompositeCodes + "," + excessInfoItem.getCompositionCode();
        }
        isExcess = excessInfoItem.getExcessMode().isExcess();
        isAbnormal = excessInfoItem.getExcessMode().isAbnormal();
        /**
         * //todo 这是是为了判断是否是唯一的污染因子代码，实际上不会遇到这种情况
         * 实际运行的时候再看
         */
        if(!alarmExcessModeKeys.contains(excessInfoItem.getExcessMode().getKey()))
        {
            // todo 测试用，没有代码
        }
        else
        {
            /**
             * todo 调试完了，把log的依耐去掉
             */
            log.info("真的有重复的if(!alarmExcessModeKeys.contains(excessInfoItem.getExcessMode().getKey()))");
        }
        return container.add(excessInfoItem);
    }

    @Override
    public boolean remove(Object o) {
        return container.remove(o);
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
        return container.containsAll(collection);
    }

    @Override
    public boolean addAll(Collection<? extends ExcessInfoItem> collection) {
        return container.containsAll(collection);
    }

    @Override
    public boolean addAll(int i, Collection<? extends ExcessInfoItem> collection) {
        return container.addAll(i, collection);
    }

    @Override
    public boolean removeAll(Collection<?> collection) {
        return container.removeAll(collection);
    }

    @Override
    public boolean retainAll(Collection<?> collection) {
        return container.retainAll(collection);
    }

    @Override
    public void clear() {
        container.clear();
    }

    @Override
    public ExcessInfoItem get(int i) {
        return container.get(i);
    }

    @Override
    public ExcessInfoItem set(int i, ExcessInfoItem excessInfoItem) {
        return container.set(i, excessInfoItem);
    }

    @Override
    public void add(int i, ExcessInfoItem excessInfoItem) {
        container.add(i, excessInfoItem);
    }

    @Override
    public ExcessInfoItem remove(int i) {
        return container.remove(i);
    }

    @Override
    public int indexOf(Object o) {
        return container.indexOf(o);
    }

    @Override
    public int lastIndexOf(Object o) {
        return container.lastIndexOf(o);
    }

    @Override
    public ListIterator<ExcessInfoItem> listIterator() {
        return container.listIterator();
    }

    @Override
    public ListIterator<ExcessInfoItem> listIterator(int i) {
        return container.listIterator(i);
    }

    @Override
    public List<ExcessInfoItem> subList(int i, int i1) {
        return container.subList(i, i1);
    }

    public String getAlarmExcessModeKeys() {
        return alarmExcessModeKeys;
    }

    public String getAlarmCompositeCodes() {
        return alarmCompositeCodes;
    }

}
